{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from PIL import Image\n",
    "import os, glob\n",
    "import numpy as np\n",
    "# from sklearn import cross_validation\n",
    "from sklearn import model_selection\n",
    "\n",
    "classes = [\"monkey\",\"boar\",\"crow\"]\n",
    "num_classes = len(classes)\n",
    "image_size = 50\n",
    "\n",
    "# 画像の読み込み\n",
    "X = []\n",
    "Y = []\n",
    "for index, classlabel in enumerate(classes):\n",
    "    photos_dir = \"./\" + classlabel\n",
    "    files = glob.glob(photos_dir + \"/*.jpg\")\n",
    "    for i, file in enumerate(files):\n",
    "        if i >= 200: break\n",
    "        image = Image.open(file)\n",
    "        image = image.convert(\"RGB\")\n",
    "        image = image.resize((image_size, image_size))\n",
    "        data = np.asarray(image)\n",
    "        X.append(data)\n",
    "        Y.append(index)\n",
    "\n",
    "X = np.array(X)\n",
    "Y = np.array(Y)\n",
    "\n",
    "X_train, X_test, y_train, y_test = model_selection.train_test_split(X, Y)\n",
    "xy = (X_train, X_test, y_train, y_test)\n",
    "np.save(\"./animal.npy\", xy)                                          "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[139, 163, 191],\n",
       "        [137, 158, 185],\n",
       "        [141, 161, 186],\n",
       "        ...,\n",
       "        [177, 199, 222],\n",
       "        [219, 231, 247],\n",
       "        [229, 242, 255]],\n",
       "\n",
       "       [[138, 164, 191],\n",
       "        [142, 166, 190],\n",
       "        [145, 167, 190],\n",
       "        ...,\n",
       "        [227, 244, 255],\n",
       "        [232, 246, 255],\n",
       "        [227, 241, 252]],\n",
       "\n",
       "       [[143, 169, 194],\n",
       "        [144, 168, 192],\n",
       "        [147, 169, 192],\n",
       "        ...,\n",
       "        [233, 247, 255],\n",
       "        [230, 244, 253],\n",
       "        [228, 242, 253]],\n",
       "\n",
       "       ...,\n",
       "\n",
       "       [[154, 176, 200],\n",
       "        [158, 180, 204],\n",
       "        [161, 183, 207],\n",
       "        ...,\n",
       "        [ 96,  97, 101],\n",
       "        [105, 100, 104],\n",
       "        [115, 113, 116]],\n",
       "\n",
       "       [[155, 175, 200],\n",
       "        [161, 181, 206],\n",
       "        [166, 186, 211],\n",
       "        ...,\n",
       "        [ 97,  98, 102],\n",
       "        [106, 107, 111],\n",
       "        [ 82,  81,  86]],\n",
       "\n",
       "       [[154, 174, 199],\n",
       "        [152, 172, 197],\n",
       "        [154, 174, 199],\n",
       "        ...,\n",
       "        [ 64,  67,  72],\n",
       "        [ 94,  95,  99],\n",
       "        [134, 138, 141]]], dtype=uint8)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train[100]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train[100]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train[200]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train[102]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
